//
//  PKLiveViewController.swift
//  Panku
//
//  Created by mac on 2017/2/10.
//  Copyright © 2017年 Monster. All rights reserved.
//

import UIKit
import YYKit
import SnapKit

private let PKLiveWatchPersonViewCellID = "PKLiveWatchPersonViewCellID"

class PKLiveViewController: PKBaseViewController {

    //MARK: - properties
    //UI
    lazy var starView = PKLiveStarView(name: "当你沉默", watchingCount: 2451)
    lazy var mCoinView = PKLiveMCoinButton.createButton()
    lazy var chatView = PKLiveChatWindowView()
    
    lazy var watchingPersonView = PKBaseCollectionView { (layout) in
        
    }
    
    lazy var dismissButton = PKBaseButton.createButton()
    lazy var accountLabel = UILabel()
    lazy var lastingTimeLabel = UILabel()
    lazy var giftButton = PKBaseButton.createButton()
    lazy var followButton = PKBaseButton.createButton()
    lazy var socialShareButton = PKBaseButton.createButton()
    lazy var switchScreenButton = PKBaseButton.createButton()
    
    //MARK: - life circle
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
    }

    //MARK: - setupUI
    override func setupRootView() {
        view.backgroundColor = UIColor.lightGray
    }
    
    override func setupSubViews() {
        view.addSubview(starView)
        view.addSubview(mCoinView)
        view.addSubview(chatView)
        view.addSubview(watchingPersonView)
        view.addSubview(dismissButton)
        
        view.addSubview(accountLabel)
        view.addSubview(lastingTimeLabel)
        view.addSubview(giftButton)
        view.addSubview(followButton)
        view.addSubview(socialShareButton)
        view.addSubview(switchScreenButton)
        
        giftButton.setImage(R.image.live_gift(), for: .normal)
        giftButton.addBlock(for: .touchUpInside) { (_) in
            //TODO:发礼物
        }
        
        followButton.setImage(R.image.live_follow(), for: .normal)
        followButton.addBlock(for: .touchUpInside) { (_) in
            //TODO:关注

        }
        
        socialShareButton.setImage(R.image.live_socialShare(), for: .normal)
        socialShareButton.addBlock(for: .touchUpInside) { (_) in
            //TODO:社交分享

        }
        
        switchScreenButton.setImage(R.image.live_zoom(), for: .normal)
        switchScreenButton.addBlock(for: .touchUpInside) { (_) in
            //TODO:切换屏幕

        }
        
        watchingPersonView.delegate = self
        watchingPersonView.dataSource = self
        watchingPersonView.register(PKLiveWatchPersonViewCell.self, forCellWithReuseIdentifier: PKLiveWatchPersonViewCellID)
        
        dismissButton.addBlock(for: .touchUpInside) { (_) in
            //TODO:dismiss
        }
        
    }
    
    override func setupSubViewsConstraints() {
        starView.snp.makeConstraints { (make) in
            make.top.equalTo(view.snp.top).offset(16)
            make.left.equalTo(view.snp.left).offset(24)
        }
        
        mCoinView.snp.makeConstraints { (make) in
            make.left.equalTo(starView.snp.left)
            make.top.equalTo(starView.snp.bottom).offset(20)
        }
        
        chatView.snp.makeConstraints { (make) in
            make.left.equalTo(view.snp.left)
            make.bottom.equalTo(view.snp.bottom).offset(-25)
            make.width.equalTo(200)
            make.height.equalTo(200)
        }
        
        dismissButton.snp.makeConstraints { (make) in
            make.right.equalTo(view.snp.right).offset(25)
            make.top.equalTo(view.snp.top).offset(25)
            make.width.equalTo(44)
            make.height.equalTo(44)
        }
        
        watchingPersonView.snp.makeConstraints { (make) in
            make.top.equalTo(dismissButton.snp.top)
            make.right.equalTo(dismissButton.snp.left)
            make.height.equalTo(100)
            make.left.equalTo(starView.snp.right)
        }
        
        switchScreenButton.snp.makeConstraints { (make) in
            make.right.equalTo(view.snp.right).offset(-20)
            make.bottom.equalTo(view.snp.bottom).offset(-24)
            make.width.equalTo(44)
            make.height.equalTo(44)
        }
        
        socialShareButton.snp.makeConstraints { (make) in
            make.bottom.equalTo(switchScreenButton.snp.bottom)
            make.right.equalTo(switchScreenButton.snp.left).offset(-20)
            make.width.equalTo(44)
            make.height.equalTo(44)
        }
        
        followButton.snp.makeConstraints { (make) in
            make.bottom.equalTo(socialShareButton.snp.bottom)
            make.right.equalTo(socialShareButton.snp.left).offset(-20)
            make.width.equalTo(44)
            make.height.equalTo(44)
        }
        
        giftButton.snp.makeConstraints { (make) in
            make.bottom.equalTo(followButton.snp.bottom)
            make.right.equalTo(followButton.snp.left).offset(-20)
            make.width.equalTo(44)
            make.height.equalTo(44)
        }

    }
    
    override func setupNavigationBar() {
        
    }
    
    override func bindViewModel() {
        
    }

}

extension PKLiveViewController:UICollectionViewDataSource,UICollectionViewDelegate{
    func numberOfSections(in collectionView: UICollectionView) -> Int {
        return 1
    }
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 10
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: PKLiveWatchPersonViewCellID, for: indexPath)
        return cell
    }
    
    func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
        
    }
    
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        
    }
}
